<template>
  <div>
    <label for="txt">姓名：</label>
    <input id="txt" type="text" v-model="text">
    <div class="s-block">
      <span @click="incrementCount"> + </span>
      <span @click="decrementCount"> - </span>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    name: {
      type: String,
      default: () => ''
    },
    count: {
      type: Number,
    }
  },
  data () {
    return {
      text: '',
      childCount: 0
    }
  },
  watch: {
    text (newVal, oldVal) {
      this.$emit('update:name', newVal)
    },
    childCount (newVal) {
      if (newVal >= 0) this.$emit('update:count', newVal)
    }
  },
  methods: {
    incrementCount () {
      this.childCount ++
    },
    decrementCount () {
      this. childCount --
    }
  }
}
</script>

<style lang="stylus" scoped>
  .s-block {
    margin 40px 0;
    span {
      display inline-block;
      border 1px solid #e1e1e1;
      padding 3px 5px;
      &:hover {
        cursor pointer;
      }
    }
  }
</style>
